#region File header

// Project: SharpWind, File: GuiManager.cs
// Namespace: SharpWind.Gui, Class: GuiManager
// Path: F:\Coder\Projekty\Windows\Dyplom\SharpWind\src\SharpWind\Gui, Author: Sebastian Haba (sho@gisz.net.pl)
// Code lines: 140, Size of file: 3,27 KB
// Creation date: 2007-03-29 12:38
// Last modified: 2007-04-01 13:13

#endregion

#region Using directives

using System.Collections.Generic;

using Microsoft.DirectX.Direct3D;

using SharpWind.Gui.Controls;
using SharpWind.Input;

#endregion

namespace SharpWind.Gui
{
	public class GuiManager
	{
		private List<Control> controls = new List<Control>();

		private Theme theme = null;

		private MouseCursor mouseCursor = null;

		private Control controlWithFocus = null;
		
		public Theme Theme
		{
			get
			{
				return theme;
			}
			set
			{
				theme = value;
			}
		}

		internal GuiManager()
		{
			Theme = Theme.Default;
			Cursor = new MouseCursor();

			Engine.Instance.Input.Mouse.Move        += new MouseEventHandler( OnMouseMove );
			Engine.Instance.Input.Mouse.ButtonDown  += new MouseEventHandler( OnMouseDown );
			Engine.Instance.Input.Mouse.ButtonUp    += new MouseEventHandler( OnMouseUp );
			Engine.Instance.Input.Mouse.ButtonPress += new MouseEventHandler( OnMousePress );
			Engine.Instance.Input.Keyboard.KeyDown  += new KeyboardEventHandler( OnKeyDown );
		}

		private void OnMouseMove( Mouse mouse, MouseEventArgs e )
		{
			Cursor.MouseMove( e );

			foreach( Control control in this.controls )
			{
				control.MouseMove( e );
			}
		}

		private void OnMousePress( Mouse mouse, MouseEventArgs e )
		{
			Cursor.MousePress( e );

			foreach( Control control in this.controls )
			{
				control.MousePress( e );
			}
		}

		/// <summary>
		/// On mouse down
		/// </summary>
		/// <param name="mouse">Mouse</param>
		/// <param name="e">E</param>
		private void OnMouseDown( Mouse mouse, MouseEventArgs e )
		{
			Cursor.MouseDown( e );

			foreach( Control control in this.controls )
			{
				control.MouseDown( e );
			} // foreach (control)
		} // OnMouseDown(mouse, e)

		/// <summary>
		/// On mouse up
		/// </summary>
		/// <param name="mouse">Mouse</param>
		/// <param name="e">E</param>
		private void OnMouseUp( Mouse mouse, MouseEventArgs e )
		{
			Cursor.MouseUp( e );

			foreach( Control control in this.controls )
			{
				control.MouseUp( e );
			} // foreach (control)
		} // OnMouseUp(mouse, e)

		/// <summary>
		/// On key down
		/// </summary>
		/// <param name="keyboard">Keyboard</param>
		/// <param name="e">E</param>
		private void OnKeyDown( Keyboard keyboard, KeyboardEventArgs e )
		{
			foreach( Control control in controls )
			{
				control.KeyDown( e );
			}
		} // OnKeyDown(keyboard, e)

		/// <summary>
		/// Add
		/// </summary>
		/// <param name="control">Control</param>
		public void Add( Control control )
		{
			this.controls.Add( control );
		} // Add(control)

		/// <summary>
		/// Render
		/// </summary>
		internal void Render()
		{
			foreach( Control control in this.controls )
			{
				control.Render();
			} // foreach (control)

			Engine.Instance.Console.Render();

			Cursor.Render();
			
		} // Render()

		public MouseCursor Cursor
		{
			get
			{
				return this.mouseCursor;
			}
			private set
			{
				this.mouseCursor = value;
			}
		}

		/// <summary>
		/// Control with focus
		/// </summary>
		/// <returns>Control</returns>
		internal Control ControlWithFocus
		{
			get
			{
				return this.controlWithFocus;
			} // get
			set
			{
				this.controlWithFocus = value;
			} // set
		} // ControlWithFocus
	}
}